home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / share / 17 / dings_e.exe / Compiler / Include / STDLIB.H < prev    next >
C/C++ Source or Header  |  1999-11-07  |  10KB  |  382 lines

  1. /*
  2.  * stdlib.h
  3.  *
  4.  * Definitions for common types, variables, and functions.
  5.  *
  6.  * This file is part of the Mingw32 package.
  7.  *
  8.  * Contributors:
  9.  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  10.  *
  11.  *  THIS SOFTWARE IS NOT COPYRIGHTED
  12.  *
  13.  *  This source code is offered for use in the public domain. You may
  14.  *  use, modify or distribute it freely.
  15.  *
  16.  *  This code is distributed in the hope that it will be useful but
  17.  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18.  *  DISCLAMED. This includes but is not limited to warranties of
  19.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * $Revision: 1.16 $
  22.  * $Author: khan $
  23.  * $Date: 1999/06/15 00:47:30 $
  24.  *
  25.  */
  26.  
  27. #ifndef _STDLIB_H_
  28. #define _STDLIB_H_
  29.  
  30. /* All the headers include this file. */
  31. #include <_mingw.h>
  32.  
  33.  
  34. #define __need_size_t
  35. #define __need_wchar_t
  36. #define __need_NULL
  37. #ifndef RC_INVOKED
  38. #include <stddef.h>
  39. #endif /* RC_INVOKED */
  40.  
  41. /*
  42.  * RAND_MAX is the maximum value that may be returned by rand.
  43.  * The minimum is zero.
  44.  */
  45. #define    RAND_MAX    0x7FFF
  46.  
  47. /*
  48.  * These values may be used as exit status codes.
  49.  */
  50. #define    EXIT_SUCCESS    0
  51. #define    EXIT_FAILURE    -1
  52.  
  53. /*
  54.  * Definitions for path name functions.
  55.  * NOTE: All of these values have simply been chosen to be conservatively high.
  56.  *       Remember that with long file names we can no longer depend on
  57.  *       extensions being short.
  58.  */
  59. #ifndef __STRICT_ANSI__
  60.  
  61. #ifndef MAX_PATH
  62. #define    MAX_PATH    (260)
  63. #endif
  64.  
  65. #define    _MAX_PATH    MAX_PATH
  66. #define    _MAX_DRIVE    (3)
  67. #define    _MAX_DIR    256
  68. #define    _MAX_FNAME    256
  69. #define    _MAX_EXT    256
  70.  
  71. #endif    /* Not __STRICT_ANSI__ */
  72.  
  73.  
  74. #ifndef RC_INVOKED
  75.  
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79.  
  80. /*
  81.  * This seems like a convenient place to declare these variables, which
  82.  * give programs using WinMain (or main for that matter) access to main-ish
  83.  * argc and argv. environ is a pointer to a table of environment variables.
  84.  * NOTE: Strings in _argv and environ are ANSI strings.
  85.  */
  86. extern int    _argc;
  87. extern char**    _argv;
  88.  
  89. /* imports from runtime dll of the above variables */
  90. #ifdef __MSVCRT__
  91.  
  92. extern int*     __p___argc(void);
  93. extern char***   __p___argv(void);
  94. extern wchar_t***   __p___wargv(void);
  95.  
  96. #define __argc (*__p___argc())
  97. #define __argv (*__p___argv())
  98. #define __wargv (*__p___wargv())
  99.  
  100. #else /* !MSVCRT */
  101.  
  102. #ifndef __DECLSPEC_SUPPORTED
  103.  
  104. extern int*    __imp___argc_dll;
  105. extern char***  __imp___argv_dll;
  106. #define __argc (*__imp___argc_dll)
  107. #define __argv (*__imp___argv_dll)
  108.  
  109. #else /* __DECLSPEC_SUPPORTED */
  110.  
  111. __MINGW_IMPORT int    __argc_dll;
  112. __MINGW_IMPORT char**  __argv_dll;
  113. #define __argc __argc_dll
  114. #define __argv __argv_dll
  115.  
  116. #endif /* __DECLSPEC_SUPPORTED */
  117.  
  118. #endif /* __MSVCRT */
  119.  
  120. /* 
  121.  * MS likes to declare errno in stdlib.h as well. 
  122.  */
  123.  
  124. #ifdef _UWIN
  125. #undef errno
  126. extern int errno;
  127. #else
  128. int*    _errno();
  129. #define    errno        (*_errno())
  130. #endif
  131. int*    __doserrno();
  132. #define    _doserrno    (*__doserrno())
  133.  
  134. /*
  135.  * Use environ from the DLL, not as a global. 
  136.  */
  137.  
  138. #ifdef __MSVCRT__
  139.   extern char *** __p__environ();
  140.   extern wchar_t *** __p__wenviron();
  141. # define _environ (*__p__environ())
  142. # define _wenviron (*__p__wenviron())
  143. #else /* ! __MSVCRT__ */
  144. # ifndef __DECLSPEC_SUPPORTED
  145.     extern char *** __imp__environ_dll;
  146. #   define _environ (*__imp__environ_dll)
  147. # else /* __DECLSPEC_SUPPORTED */
  148.     __MINGW_IMPORT char ** _environ_dll;
  149. #   define _environ _environ_dll
  150. # endif /* __DECLSPEC_SUPPORTED */
  151. #endif /* ! __MSVCRT__ */
  152.  
  153. #define environ _environ
  154.  
  155. #ifdef    __MSVCRT__
  156. /* One of the MSVCRTxx libraries */
  157.  
  158. #ifndef __DECLSPEC_SUPPORTED
  159.   extern int*    __imp__sys_nerr;
  160. # define    sys_nerr    (*__imp__sys_nerr)
  161. #else /* __DECLSPEC_SUPPORTED */
  162.   __MINGW_IMPORT int    _sys_nerr;
  163. # ifndef _UWIN
  164. #   define    sys_nerr    _sys_nerr
  165. # endif /* _UWIN */
  166. #endif /* __DECLSPEC_SUPPORTED */
  167.  
  168. #else /* ! __MSVCRT__ */
  169.  
  170. /* CRTDLL run time library */
  171.  
  172. #ifndef __DECLSPEC_SUPPORTED
  173.   extern int*    __imp__sys_nerr_dll;
  174. # define sys_nerr    (*__imp__sys_nerr_dll)
  175. #else /* __DECLSPEC_SUPPORTED */
  176.   __MINGW_IMPORT int    _sys_nerr_dll;
  177. # define sys_nerr    _sys_nerr_dll
  178. #endif /* __DECLSPEC_SUPPORTED */
  179.  
  180. #endif /* ! __MSVCRT__ */
  181.  
  182. #ifndef __DECLSPEC_SUPPORTED
  183. extern char***    __imp__sys_errlist;
  184. #define    sys_errlist    (*__imp__sys_errlist)
  185. #else /* __DECLSPEC_SUPPORTED */
  186. __MINGW_IMPORT char*    _sys_errlist[];
  187. #ifndef _UWIN
  188. #define    sys_errlist    _sys_errlist
  189. #endif /* _UWIN */
  190. #endif /* __DECLSPEC_SUPPORTED */
  191.  
  192. /*
  193.  * OS version and such constants.
  194.  */
  195. #ifndef __STRICT_ANSI__
  196.  
  197. #ifdef    __MSVCRT__
  198. /* msvcrtxx.dll */
  199.  
  200. extern unsigned int*    __p__osver();
  201. extern unsigned int*    __p__winver();
  202. extern unsigned int*    __p__winmajor();
  203. extern unsigned int*    __p__winminor();
  204.  
  205. #define _osver        (*__p__osver())
  206. #define _winver        (*__p__winver())
  207. #define _winmajor    (*__p__winmajor())
  208. #define _winminor    (*__p__winminor())
  209.  
  210. #else
  211. /* Not msvcrtxx.dll, thus crtdll.dll */
  212.  
  213. #ifndef __DECLSPEC_SUPPORTED
  214.  
  215. extern unsigned int*    _imp___osver_dll;
  216. extern unsigned int*    _imp___winver_dll;
  217. extern unsigned int*    _imp___winmajor_dll;
  218. extern unsigned int*    _imp___winminor_dll;
  219.  
  220. #define _osver        (*_imp___osver_dll)
  221. #define _winver        (*_imp___winver_dll)
  222. #define _winmajor    (*_imp___winmajor_dll)
  223. #define _winminor    (*_imp___winminor_dll)
  224.  
  225. #else /* __DECLSPEC_SUPPORTED */
  226.  
  227. __MINGW_IMPORT unsigned int    _osver_dll;
  228. __MINGW_IMPORT unsigned int    _winver_dll;
  229. __MINGW_IMPORT unsigned int    _winmajor_dll;
  230. __MINGW_IMPORT unsigned int    _winminor_dll;
  231.  
  232. #define _osver        _osver_dll
  233. #define _winver        _winver_dll
  234. #define _winmajor    _winmajor_dll
  235. #define _winminor    _winminor_dll
  236.  
  237. #endif /* __DECLSPEC_SUPPORTED */
  238.  
  239. #endif
  240.  
  241. #endif /* Not __STRICT_ANSI__ */
  242.  
  243. #ifdef    __GNUC__
  244. #define    _ATTRIB_NORETURN    __attribute__ ((noreturn))
  245. #else    /* Not __GNUC__ */
  246. #define    _ATTRIB_NORETURN
  247. #endif    /* __GNUC__ */
  248.  
  249. double    atof    (const char* szNumber);
  250. int    atoi    (const char* szNumber);
  251. long    atol    (const char* szNumber);
  252.  
  253. double    strtod    (const char* szNumber, char** pszAfterNumber);
  254. double    wcstod    (const wchar_t* wsNumber, wchar_t** pwsAfterNumber);
  255. long    strtol    (const char* szNumber, char** pszAfterNumber, int nBase);
  256. long    wcstol    (const wchar_t* wsNumber, wchar_t** pwsAfterNumber, int nBase);
  257.  
  258. unsigned long    strtoul    (const char* szNumber, char** pszAfterNumber,
  259.             int nBase);
  260. unsigned long    wcstoul (const wchar_t* wsNumber, wchar_t** pwsAfterNumber,
  261.             int nBase);
  262.  
  263. size_t    wcstombs    (char* mbsDest, const wchar_t* wsConvert, size_t size);
  264. int    wctomb        (char* mbDest, wchar_t wc);
  265.  
  266. int    mblen        (const char* mbs, size_t sizeString);
  267. size_t    mbstowcs    (wchar_t* wcaDest, const char* mbsConvert,
  268.              size_t size);
  269. int    mbtowc        (wchar_t* wcDest, const char* mbConvert, size_t size);
  270.  
  271. int    rand    ();
  272. void    srand    (unsigned int nSeed);
  273.  
  274. void*    calloc    (size_t sizeObjCnt, size_t sizeObject);
  275. void*    malloc    (size_t    sizeObject);
  276. void*    realloc    (void* pObject, size_t sizeNew);
  277. void    free    (void* pObject);
  278.  
  279. void    abort    () _ATTRIB_NORETURN;
  280. void    exit    (int nStatus) _ATTRIB_NORETURN;
  281. int    atexit    (void (*pfuncExitProcessing)(void));
  282.  
  283. int    system    (const char* szCommand);
  284. char*    getenv    (const char* szVarName);
  285.  
  286. typedef    int (*_pfunccmp_t)(const void*, const void*);
  287.  
  288. void*    bsearch    (const void* pKey, const void* pBase, size_t cntObjects,
  289.         size_t sizeObject, _pfunccmp_t pfuncCmp);
  290. void    qsort    (const void* pBase, size_t cntObjects, size_t sizeObject,
  291.         _pfunccmp_t pfuncCmp);
  292.  
  293. int    abs    (int n);
  294. long    labs    (long n);
  295.  
  296. /*
  297.  * div_t and ldiv_t are structures used to return the results of div and
  298.  * ldiv.
  299.  *
  300.  * NOTE: div and ldiv appear not to work correctly unless
  301.  *       -fno-pcc-struct-return is specified. This is included in the
  302.  *       mingw32 specs file.
  303.  */
  304. typedef struct { int quot, rem; } div_t;
  305. typedef struct { long quot, rem; } ldiv_t;
  306.  
  307. div_t    div    (int nNumerator, int nDenominator);
  308. ldiv_t    ldiv    (long lNumerator, long lDenominator);
  309.  
  310.  
  311. #ifndef    __STRICT_ANSI__
  312.  
  313. /*
  314.  * NOTE: Officially the three following functions are obsolete. The Win32 API
  315.  *       functions SetErrorMode, Beep and Sleep are their replacements.
  316.  */
  317. void    _beep (unsigned int, unsigned int);
  318. void    _seterrormode (int nMode);
  319. void    _sleep (unsigned long ulTime);
  320.  
  321. void    _exit    (int nStatus) _ATTRIB_NORETURN;
  322.  
  323. int    _putenv    (const char* szNameEqValue);
  324. void    _searchenv (const char* szFileName, const char* szVar,
  325.         char* szFullPathBuf);
  326.  
  327. char*    _itoa (int nValue, char* sz, int nRadix);
  328. char*    _ltoa (long lnValue, char* sz, int nRadix);
  329.  
  330. char*    _ecvt (double dValue, int nDig, int* pnDec, int* pnSign);
  331. char*    _fcvt (double dValue, int nDig, int* pnDec, int* pnSign);
  332. char*    _gcvt (double dValue, int nDec, char* caBuf);
  333.  
  334. void    _makepath (char* caPath, const char* szDrive, const char* szDir,
  335.         const char* szName, const char* szExtension);
  336. void    _splitpath (const char* szPath, char* caDrive, char* caDir,
  337.         char* caName, char* caExtension);
  338. char*    _fullpath (char* caBuf, const char* szPath, size_t sizeMax);
  339. int    _wtoi (const wchar_t *);
  340. long    _wtol (const wchar_t *);
  341.  
  342. char*    _i64toa(__int64, char *, int);
  343. char*    _ui64toa(unsigned __int64, char *, int);
  344. __int64    _atoi64(const char *);
  345.  
  346. wchar_t* _i64tow(__int64, wchar_t *, int);
  347. wchar_t* _ui64tow(unsigned __int64, wchar_t *, int);
  348. __int64    _wtoi64(const wchar_t *);
  349.  
  350.  
  351. #ifndef    _NO_OLDNAMES
  352.  
  353. int    putenv (const char* szNameEqValue);
  354. void    searchenv (const char* szFileName, const char* szVar,
  355.         char* szFullPathBuf);
  356.  
  357. char*    itoa (int nValue, char* sz, int nRadix);
  358. char*    ltoa (long lnValue, char* sz, int nRadix);
  359.  
  360. #ifndef _UWIN
  361. char*    ecvt (double dValue, int nDig, int* pnDec, int* pnSign);
  362. char*    fcvt (double dValue, int nDig, int* pnDec, int* pnSign);
  363. char*    gcvt (double dValue, int nDec, char* caBuf);
  364. #endif /* _UWIN */
  365. #endif    /* Not _NO_OLDNAMES */
  366.  
  367. #endif    /* Not __STRICT_ANSI__ */
  368.  
  369. /*
  370.  * Undefine the no return attribute used in some function definitions
  371.  */
  372. #undef    _ATTRIB_NORETURN
  373.  
  374. #ifdef __cplusplus
  375. }
  376. #endif
  377.  
  378. #endif    /* Not RC_INVOKED */
  379.  
  380. #endif    /* Not _STDLIB_H_ */
  381.  
  382.